package com.addressbook.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.addressbook.fw.GroupData;
import com.addressbook.utils.SortedListOf;
import static com.addressbook.tests.GroupDataGenerator.loadsGroupsFromXmlFile;
//import static com.addressbook.tests.GroupDataGenerator.loadsGroupsFromCsvFile;

public class GroupCreationTests extends TestBase {

	@DataProvider
    public static Iterator<Object[]> getValidGroupsFromFile() throws IOException {
            return wrapGroupDataForDataProvider(
                            loadsGroupsFromXmlFile(new File("groups.xml"))).iterator();
//            				loadsGroupsFromCsvFile(new File("groups.txt"))).iterator();
    }
	
	@Test(dataProvider = "getValidGroupsFromFile")
	public void testGroupCreationValidData(GroupData group) throws Exception {
		// save old
		SortedListOf<GroupData> oldstate = new SortedListOf<GroupData> (app.getHibernateHelper().listGroups());

		app.getGroupHelper().createGroup(group);

		// save new
		SortedListOf<GroupData> newstate = app.getGroupHelper().getGroupsName();

		// check
		assertThat(newstate, equalTo(oldstate.withAdded(group)));
	}
}